package edu.upenn.yas;

import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddFriendAction extends ActionSupport {
    private String friend;
    private String result;

    public String execute() {
        Map session = ActionContext.getContext().getSession();
        if (session.get("login") != null) {
            String username = (String)session.get("username");
            boolean success = 
                QueryEngine.instance.addFriend(username, friend);
            if (success) {
                result = "Friend added!";
                return SUCCESS;
            } else {
                result = "Friend does not exist.";
                return ERROR;
            }
        }
        result = "Not logged in.";
        return ERROR;
    }

    public String getFriend() { return friend; }
    public void setFriend(String friend) { this.friend = friend; }
    public String getResult() { return result; }
    public void setResult(String result) { this.result = result; }
}
